package com.poi.demopoi.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.poi.demopoi.config.page.PageResultDTO;
import com.poi.demopoi.config.page.SmartPageUtil;
import com.poi.demopoi.controller.EmployeeDTO2;
import com.poi.demopoi.domain.Employee;
import com.poi.demopoi.domain.EmployeeDto;
import com.poi.demopoi.domain.EmployeeVO;
import com.poi.demopoi.mapper.EmployeeMapper;
import com.poi.demopoi.service.IEmployeeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lx
 * @since 2020-06-03
 */
@Service
//@Transactional(rollbackFor = Exception.class)
public class EmployeeImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {

    //    @Autowired
    @Resource
    EmployeeMapper employeeMapper;


    @Override
    public int batchUpdateList(List<Employee> userList) {
        return baseMapper.batchUpdateList(userList);
    }

    @Override
    public int batchSaveList(List<Employee> userList) {
        return baseMapper.batchSaveList(userList);
    }

    /**
     * @author yandanyang
     * @description 分页查询
     * @date 2019-07-11 16:19:48
     */
    @Override
    public PageResultDTO<Employee> queryByPage(EmployeeDTO2 queryDTO) {
//        queryDTO.setDeleted(JudgeEnum.NO.getValue());
        Page page = SmartPageUtil.convert2QueryPage(queryDTO);
        List<Employee> dtoList = employeeMapper.queryByPage(page, queryDTO);
        page.setRecords(dtoList);
        PageResultDTO<Employee> pageResultDTO = SmartPageUtil.convert2PageResult(page);
        return pageResultDTO;
    }


    @Override
    public IPage<Employee> getUsersWithRolePage(Page page, Employee userDTO) {

//        if (ObjectUtil.isNotNull(userDTO) && userDTO.getAge() != 0) {
//            userDTO.setName(userDTO.getName());
//        }
//        return baseMapper.selectPage(new Page<>(pageNo, pageSize), lambdaQuery);

//        page.setOrders();

        return baseMapper.getUserVosPage(page, userDTO);
    }


    @Override
    public List<Employee> selectEmployeePagesRuoyi(Employee employee) {
        return employeeMapper.selectEmployeePagesRuoyi(employee);
    }


    @Override
    public List<EmployeeVO> findPagesLogical(EmployeeDto dto, int start, int end) {
        return baseMapper.findPagesLogical(dto, start, end);
    }


    //    @Override
    public IPage<Employee> findPages3(EmployeeDto dto, Integer pageNo, Integer pageSize, String state, String itemName) {
        String name = dto.getName();
        LambdaQueryWrapper<Employee> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.like(StringUtils.isNotBlank(name), Employee::getName, name);
        lambdaQuery.orderByDesc(Employee::getAge);
        return baseMapper.selectPage(new Page<>(pageNo, pageSize), lambdaQuery);
    }


    @Override
    public IPage<Employee> getUsersWithRolePage02(Page page, Wrapper<Employee> queryWrapper) {
        IPage<Employee> iPage = baseMapper.selectPage(page, queryWrapper);
        return iPage;
    }


//    @Override
//    public Employee findCart_by_ugm(int userId, int goodsId, Integer specId) {
//        LambdaQueryWrapper<Employee> wrapper = Wrappers.lambdaQuery();
//        wrapper.eq(Employee::getUserId, userId);
//        wrapper.eq(Employee::getGoodsId, goodsId);
//        wrapper.eq(Employee::getMiddleSpecId, specId);
//        Employee one = getOne(wrapper);
//        return one;
//    }
//
//    @Override
//    public Employee find_cart_byCartId(Integer cartId) {
//        return getById(cartId);
//    }
//
//    @Override
//    public int update_cart_number(int number, Integer cartId) {
//        Employee oo = new Employee();
//        oo.setGoodsNum(number);
//        LambdaQueryWrapper<Employee> lambdaQuery = Wrappers.lambdaQuery();
//        lambdaQuery.eq(Employee::getCartId, cartId);
//        int update = employeeMapper.update(oo, lambdaQuery);
//        return update;
//    }
//
//    @Override
//    public List<Employee> findAll_cart() {
//        return list();
//    }
//
//    @Override
//    public int update_cart_by_postJsonArray(int goods_num, int select, int cartId) {
//        Employee oo = new Employee();
//        oo.setGoodsNum(goods_num);
//        oo.setSelected(select);
//        oo.setCartId(cartId);
//        int update = employeeMapper.updateById(oo);
//        return update;
//    }
//
//    @Override
//    public int deleteCart_afterSubmitOrder(int user_id) {
//        LambdaQueryWrapper<Employee> lambdaQuery = Wrappers.lambdaQuery();
//        lambdaQuery.eq(Employee::getUserId, user_id);
//        lambdaQuery.eq(Employee::getSelected, 1);
//        int delete = employeeMapper.delete(lambdaQuery);
//        return delete;
//    }
//
//    @Override
//    public List<Employee> findCartList_withChecked() {
//        LambdaQueryWrapper<Employee> lambdaQuery = Wrappers.lambdaQuery();
//        lambdaQuery.eq(Employee::getSelected, 1);
//        List<Employee> list = list(lambdaQuery);
//        return list;
//    }
//
//    @Override
//    public int findCount_selectCartPO(int userId) {
//        LambdaQueryWrapper<Employee> lambdaQuery = Wrappers.lambdaQuery();
//        lambdaQuery.eq(Employee::getSelected, 1);
//        lambdaQuery.eq(Employee::getUserId, userId);
//        return count(lambdaQuery);
//    }
}
